#include <bits/stdc++.h>

#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

template<class T>inline void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T>inline void chkmx(T &x, T y) { if (y > x) x = y; }

using namespace std;

const int maxn = 200010;
const int maxm = maxn * 20;

struct node {
  int cnt;
  ll sum;
  node() { cnt = sum = 0; }
  node(ll x) { cnt = 1, sum = x; }
  node(int x, ll y) { cnt = x, sum = y; }
  friend node operator+(node x, node y) {
    return node(x.cnt + y.cnt, x.sum + y.sum);
  }
  friend node operator-(node x, node y) {
    return node(x.cnt - y.cnt, x.sum - y.sum);
  }
} t[maxm];

int n, m, vis[maxn], ls[maxm], rs[maxm], rt[maxn], tot;
ll val[maxn];
pii a[maxn];
vector<int> h[maxn], w[maxn], dh[maxn], dw[maxn], pr, vec[maxn];

int isp(int x) {
  for (int i = 2; i * i <= x; ++i) {
    if (x % i == 0) return 0;
  }
  return 1;
}

int dis(int x, int y) {
  return max(abs(a[x].fi - a[y].fi), abs(a[x].se - a[y].se));
}

int c(int x, int y, int z) {
  return x + y + z - max(max(x, y), z) - min(min(x, y), z);
}

pii mp(int x, int y) {
  return pii(min(x, y), max(x, y));
}

#define mid ((l + r) >> 1)

void upd(int &p, int q, int l, int r, int x, node v) {
  p = ++tot, ls[p] = ls[q], rs[p] = rs[q];
  if (l == r) return t[p] = t[q] + v, void();
  if (x <= mid) upd(ls[p], ls[q], l, mid, x, v);
  else upd(rs[p], rs[q], mid + 1, r, x, v);
  t[p] = t[ls[p]] + t[rs[p]];
}

node qry(int p, int l, int r, int x, int y) {
  if (!p || (l == x && r == y)) return t[p];
  if (y <= mid) return qry(ls[p], l, mid, x, y);
  else if (x > mid) return qry(rs[p], mid + 1, r, x, y);
  else return qry(ls[p], l, mid, x, mid) + qry(rs[p], mid + 1, r, mid + 1, y);
}

#undef mid

node calc(int l, int r, int lp, int rp) {
  chkmx(l, 1), chkmn(r, m), chkmx(lp, 1), chkmn(rp, m);
  if (l > r || lp > rp) return node();
  return qry(rt[r], 1, m, lp, rp) - qry(rt[l - 1], 1, m, lp, rp);
}

void work() {
  rep (i, 1, tot) t[i] = node(), ls[i]= rs[i] = 0;
  tot = 0;
  cin >> n >> m;
  rep (i, 1, n) {
    int x, y;
    cin >> x >> y;
    a[i] = pii(x - y + m + 1, x + y);
  }
  rep (i, 1, n) cin >> val[i];
  m <<= 1;
  rep (i, 1, m) vec[i].clear(), rt[i] = 0;
  rep (i, 1, n) vec[a[i].fi].emplace_back(i);
  rep (i, 1, m) {
    rt[i] = rt[i - 1];
    for (int x : vec[i]) upd(rt[i], rt[i], 1, m, a[x].se, node(val[x]));
  }
  rep (i, 1, m) h[i].clear(), w[i].clear(), dh[i].clear(), dw[i].clear();
  rep (i, 1, n) h[a[i].fi].emplace_back(i), w[a[i].se].emplace_back(i);
  rep (i, 1, n) dh[a[i].fi].emplace_back(a[i].se), dw[a[i].se].emplace_back(a[i].fi);
  rep (i, 1, m) sort(ALL(h[i]), [&](int x, int y) { return a[x].se < a[y].se; });
  rep (i, 1, m) sort(ALL(w[i]), [&](int x, int y) { return a[x].fi < a[y].fi; });
  rep (i, 1, m) sort(ALL(dh[i])), sort(ALL(dw[i]));
  ll ans = 0;
  rep (i, 1, n) for (int d : pr) {
    int x = a[i].fi - d, l = a[i].se - d + 1, r = a[i].se + d - 1;
    if (x < 1 || x > m) break;
    int pos = lower_bound(ALL(dh[x]), l) - dh[x].begin();
    node ci = node(-1, -1);
    rep (p, pos, SZ(h[x]) - 1) {
      if (dh[x][p] > r) break;
      int j = h[x][p];
      if (j <= i) continue;
      if (ci.cnt == -1) ci = calc(a[i].fi - d, a[i].fi + d, a[i].se - d, a[i].se + d);
      ll cnt = 0, S = 0;
      node tmp = ci;
      tmp = tmp - calc(max(a[i].fi - d, a[j].fi - d + 1), min(a[i].fi + d, a[j].fi + d - 1),
                       max(a[i].se - d, a[j].se - d + 1), min(a[i].se + d, a[j].se + d - 1));
      tmp.cnt -= 1, tmp.sum -= val[i];
      cnt += tmp.cnt, S += tmp.sum;
      tmp = calc(a[j].fi - d, a[j].fi + d, a[j].se - d, a[j].se + d);
      tmp = tmp - calc(max(a[j].fi - d, a[i].fi - d + 1), min(a[j].fi + d, a[i].fi + d - 1),
                       max(a[j].se - d, a[i].se - d + 1), min(a[j].se + d, a[i].se + d - 1));
      tmp.cnt -= 1, tmp.sum -= val[j];
      cnt += tmp.cnt, S += tmp.sum;
      ans += (val[i] + val[j]) * cnt + S;
    }
  }
  rep (i, 1, n) for (int d : pr) {
    int x = a[i].fi + d, l = a[i].se - d + 1, r = a[i].se + d - 1;
    if (x < 1 || x > m) break;
    int pos = lower_bound(ALL(dh[x]), l) - dh[x].begin();
    node ci = node(-1, -1);
    rep (p, pos, SZ(h[x]) - 1) {
      if (dh[x][p] > r) break;
      int j = h[x][p];
      if (j <= i) continue;
      if (ci.cnt == -1) ci = calc(a[i].fi - d, a[i].fi + d, a[i].se - d, a[i].se + d);
      ll cnt = 0, S = 0;
      node tmp = ci;
      tmp = tmp - calc(max(a[i].fi - d, a[j].fi - d + 1), min(a[i].fi + d, a[j].fi + d - 1),
                       max(a[i].se - d, a[j].se - d + 1), min(a[i].se + d, a[j].se + d - 1));
      tmp.cnt -= 1, tmp.sum -= val[i];
      cnt += tmp.cnt, S += tmp.sum;
      tmp = calc(a[j].fi - d, a[j].fi + d, a[j].se - d, a[j].se + d);
      tmp = tmp - calc(max(a[j].fi - d, a[i].fi - d + 1), min(a[j].fi + d, a[i].fi + d - 1),
                       max(a[j].se - d, a[i].se - d + 1), min(a[j].se + d, a[i].se + d - 1));
      tmp.cnt -= 1, tmp.sum -= val[j];
      cnt += tmp.cnt, S += tmp.sum;
      ans += (val[i] + val[j]) * cnt + S;
    }
  }
  rep (i, 1, n) for (int d : pr) {
    int x = a[i].se - d, l = a[i].fi - d, r = a[i].fi + d;
    if (x < 1 || x > m) break;
    int pos = lower_bound(ALL(dw[x]), l) - dw[x].begin();
    node ci = node(-1, -1);
    rep (p, pos, SZ(w[x]) - 1) {
      if (dw[x][p] > r) break;
      int j = w[x][p];
      if (j <= i) continue;
      if (ci.cnt == -1) ci = calc(a[i].fi - d, a[i].fi + d, a[i].se - d, a[i].se + d);
      ll cnt = 0, S = 0;
      node tmp = ci;
      tmp = tmp - calc(max(a[i].fi - d, a[j].fi - d + 1), min(a[i].fi + d, a[j].fi + d - 1),
                       max(a[i].se - d, a[j].se - d + 1), min(a[i].se + d, a[j].se + d - 1));
      tmp.cnt -= 1, tmp.sum -= val[i];
      cnt += tmp.cnt, S += tmp.sum;
      tmp = calc(a[j].fi - d, a[j].fi + d, a[j].se - d, a[j].se + d);
      tmp = tmp - calc(max(a[j].fi - d, a[i].fi - d + 1), min(a[j].fi + d, a[i].fi + d - 1),
                       max(a[j].se - d, a[i].se - d + 1), min(a[j].se + d, a[i].se + d - 1));
      tmp.cnt -= 1, tmp.sum -= val[j];
      cnt += tmp.cnt, S += tmp.sum;
      ans += (val[i] + val[j]) * cnt + S;
    }
  }
  rep (i, 1, n) for (int d : pr) {
    int x = a[i].se + d, l = a[i].fi - d, r = a[i].fi + d;
    if (x < 1 || x > m) break;
    int pos = lower_bound(ALL(dw[x]), l) - dw[x].begin();
    node ci = node(-1, -1);
    rep (p, pos, SZ(w[x]) - 1) {
      if (dw[x][p] > r) break;
      int j = w[x][p];
      if (j <= i) continue;
      if (ci.cnt == -1) ci = calc(a[i].fi - d, a[i].fi + d, a[i].se - d, a[i].se + d);
      ll cnt = 0, S = 0;
      node tmp = ci;
      tmp = tmp - calc(max(a[i].fi - d, a[j].fi - d + 1), min(a[i].fi + d, a[j].fi + d - 1),
                       max(a[i].se - d, a[j].se - d + 1), min(a[i].se + d, a[j].se + d - 1));
      tmp.cnt -= 1, tmp.sum -= val[i];
      cnt += tmp.cnt, S += tmp.sum;
      tmp = calc(a[j].fi - d, a[j].fi + d, a[j].se - d, a[j].se + d);
      tmp = tmp - calc(max(a[j].fi - d, a[i].fi - d + 1), min(a[j].fi + d, a[i].fi + d - 1),
                       max(a[j].se - d, a[i].se - d + 1), min(a[j].se + d, a[i].se + d - 1));
      tmp.cnt -= 1, tmp.sum -= val[j];
      cnt += tmp.cnt, S += tmp.sum;
      ans += (val[i] + val[j]) * cnt + S;
    }
  }
  rep (i, 1, n) for (int d : pr) {
    int cnt = 0;
    ll S = 0;
    if (a[i].fi - d >= 1) {
      int x = a[i].fi - d, l = a[i].se - d + 1, r = a[i].se + d - 1;
      int pos = lower_bound(ALL(dh[x]), l) - dh[x].begin();
      rep (p, pos, SZ(h[x]) - 1) {
        if (dh[x][p] > r) break;
        cnt++, S += val[h[x][p]];
      }
    }
    if (a[i].fi + d <= m) {
      int x = a[i].fi + d, l = a[i].se - d + 1, r = a[i].se + d - 1;
      int pos = lower_bound(ALL(dh[x]), l) - dh[x].begin();
      rep (p, pos, SZ(h[x]) - 1) {
        if (dh[x][p] > r) break;
        cnt++, S += val[h[x][p]];
      }
    }
    if (a[i].se - d >= 1) {
      int x = a[i].se - d, l = a[i].fi - d, r = a[i].fi + d;
      int pos = lower_bound(ALL(dw[x]), l) - dw[x].begin();
      rep (p, pos, SZ(w[x]) - 1) {
        if (dw[x][p] > r) break;
        cnt++, S += val[w[x][p]];
      }
    }
    if (a[i].se + d <= m) {
      int x = a[i].se + d, l = a[i].fi - d, r = a[i].fi + d;
      int pos = lower_bound(ALL(dw[x]), l) - dw[x].begin();
      rep (p, pos, SZ(w[x]) - 1) {
        if (dw[x][p] > r) break;
        cnt++, S += val[w[x][p]];
      }
    }
    ans -= val[i] * cnt * (cnt - 1) / 2;
    ans -= S * (cnt - 1);
  }
  ll sum = 0;
  rep (i, 1, n) for (int d : pr) {
    vector<int> vec;
    if (a[i].fi - d >= 1) {
      int x = a[i].fi - d, l = a[i].se - d + 1, r = a[i].se + d - 1;
      int pos = lower_bound(ALL(dh[x]), l) - dh[x].begin();
      rep (p, pos, SZ(h[x]) - 1) {
        if (dh[x][p] > r) break;
        vec.emplace_back(h[x][p]);
      }
    }
    if (a[i].fi + d <= m) {
      int x = a[i].fi + d, l = a[i].se - d + 1, r = a[i].se + d - 1;
      int pos = lower_bound(ALL(dh[x]), l) - dh[x].begin();
      rep (p, pos, SZ(h[x]) - 1) {
        if (dh[x][p] > r) break;
        vec.emplace_back(h[x][p]);
      }
    }
    if (a[i].se - d >= 1) {
      int x = a[i].se - d, l = a[i].fi - d, r = a[i].fi + d;
      int pos = lower_bound(ALL(dw[x]), l) - dw[x].begin();
      rep (p, pos, SZ(w[x]) - 1) {
        if (dw[x][p] > r) break;
        vec.emplace_back(w[x][p]);
      }
    }
    if (a[i].se + d <= m) {
      int x = a[i].se + d, l = a[i].fi - d, r = a[i].fi + d;
      int pos = lower_bound(ALL(dw[x]), l) - dw[x].begin();
      rep (p, pos, SZ(w[x]) - 1) {
        if (dw[x][p] > r) break;
        vec.emplace_back(w[x][p]);
      }
    }
    for (int x : vec) for (int y : vec) if (x < y) {
      if (dis(i, x) == dis(i, y) && dis(i, x) == dis(x, y)) sum += val[x] + val[y] + val[i];
    }
  }
  cout << ans - sum / 3 * 2 << '\n';
}

int main() {
  freopen("chess.in", "r", stdin);
  freopen("chess.out", "w", stdout);
  rep (i, 2, 100000) if (isp(i)) {
    if (i <= 10 || i % 20 == 3)  vis[i] = 1, pr.emplace_back(i);
  }
  cin.tie(nullptr) -> ios::sync_with_stdio(false);
  int t; cin >> t;
  while (t--) work();
}